#include "mainwindow.h"
#include <QIcon>
#include <QAction>
#include <QToolBar>
#include <QDialog>
#include <QDebug>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle(tr("Main window"));

    openAction = new QAction(tr("&Open"), this);
    openAction->setIcon(QIcon(":/images/comment.png"));

    connect(openAction, &QAction::triggered, this, &MainWindow::open);

    QToolBar *toolBar = addToolBar(tr("File"));
    toolBar->addAction(openAction);


}

MainWindow::~MainWindow()
{

}

void MainWindow::open()
{
//    QDialog *dialog = new QDialog;
//    dialog->setAttribute(Qt::WA_DeleteOnClose);
//    dialog->setWindowTitle(tr("Hello, dialog!"));
//    dialog->show();

//    QDialog dialog(this);
//    dialog.setWindowTitle(tr("Hello, dialog"));
//    dialog.exec();
//    qDebug() << dialog.result();

//    if(QMessageBox::Yes == QMessageBox::question(this,
//                                                 tr("Question"),
//                                                 tr("Are you OK?"),
//                                                 QMessageBox::Yes | QMessageBox::No,
//                                                 QMessageBox::Yes)) {
//        QMessageBox::information(this, tr("Hmmm..."), tr("I'm glad to heart that!"));

//    } else {
//          QMessageBox::information(this, tr("Hmmm..."), tr("I'm sorry!"));
//    }
    QMessageBox msgBox;
    msgBox.setText(tr("The document has been modified."));
    msgBox.setInformativeText(tr("Do you want to save your changes?"));
    msgBox.setDetailedText(tr("Differences here..."));
    msgBox.setStandardButtons(QMessageBox::Save
                              | QMessageBox::Discard
                              | QMessageBox::Cancel);
    msgBox.setDefaultButton(QMessageBox::Save);
    int ret = msgBox.exec();
    switch(ret) {
    case QMessageBox::Save:
        qDebug() << "Save document";
        break;
    case QMessageBox::Discard:
        qDebug() << "Discard document";
        break;
    case QMessageBox::Cancel:
        qDebug() << "Cancel document";
        break;
    }

}
